package com.gok.kanmeituyun2.util.image;

import android.app.Activity;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.gok.kanmeituyun2.R;

/**
 * @Company
 * @Classname
 * @Description TODO  使用第三方组件显示图片
 * @Author wbs
 * Date 2021.6.18 15:39
 * Version 1.0
 */
public class ImageUtil {

    /**
     * @param activity
     * @param url
     * @param iv
     * @return void
     * @methodName TODO 显示图片
     * @author wbs
     * @date 2021.6.18 16:16
     */
    public static void show(Activity activity, String url, ImageView iv) {
        RequestOptions options = getRequestOptions();
        //访问远程图片服务器，取回图片并显示到指定组件上
        Glide.with(activity).load(url).apply(options).into(iv);
    }

    /**
     * @return com.bumptech.glide.request.RequestOptions
     * @methodName TODO 取得显示图片前请求的相关参数
     * @author wbs
     * @date 2021.6.18 16:16
     */
    private static RequestOptions getRequestOptions() {
        RequestOptions requestOptions = new RequestOptions();
        //加载图片时，为了给用户友好体验，需要设置图片占位符
        //加载前占位图
        requestOptions.placeholder(R.drawable.ic_place_preview);
        //加载错误图片
        requestOptions.error(R.drawable.ic_place_error);
        //测试时，禁用所有缓存
        requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);
        return requestOptions;
    }
}
